package ttt;

public class MinMax {
	private Node root;
	private int side;
	
	public MinMax(int[][] b, int side) {
		root = new Node(b);
		buildTree(side, root);		
	}
	
	private Node buildTree(int s, Node parent) {
		int[][] board = (int[][])parent.getValue();
		Node current;
		for(int r = 0; r < 3; r++) {
			for(int c = 0; c < 3; c++) {
				if (board[r][c] == -1) {
					board[r][c] = side;
					side = flip(side);
					current = new Node(board);
					parent.addChild(buildTree(side,current));
				}
			}
		}		
		return parent;
	}
	
	private int flip(int f) {
		if (f == 0)
			return 1;
		else 
			return 0;
	}

}
